package com.digitalchina.lxnsy.sy.login;

import android.view.Window;
import android.view.WindowManager;
import android.webkit.JavascriptInterface;

import com.digitalchina.lxnsy.activity.old.MainActivity;
import com.digitalchina.lxnsy.base.BaseHtmlActivity;
import com.digitalchina.lxnsy.sy.all.ForgetPasswordActivity;
import com.digitalchina.lxnsy.sy.peopleAddExp.ReviewResultsActivity;
import com.digitalchina.lxnsy.toolkit.ActivityTaskManager;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.digitalchina.lxnsy.xml.RongCloudXML;
import com.digitalchina.lxnsy.xml.UserXML;

import org.json.JSONException;
import org.json.JSONObject;
import org.lzh.framework.updatepluginlib.util.ActivityManager;

public class RegisterAndLoginActivity extends BaseHtmlActivity {
    @Override
    protected void loadHtml() {
        webView.addJavascriptObject(new JsApi(), null);
        loadUrl("login");
         hideActionBar();
    }

    @Override
    public void rightOnClick(){


    }

    @Override
    protected void setNoTitle() {
        super.setNoTitle();

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    public class JsApi {
        @JavascriptInterface
        public void index(Object msg) {


            try {
                JSONObject object1=  new JSONObject(msg.toString());
                UserXML.setLoginStatus(getApplication(),"1");
                UserXML.setMobilePhone(getApplication(),object1.getString("mobilePhone"));
                UserXML.setLoginName(getApplication(),object1.getString("loginName"));
                UserXML.setName(getApplication(),object1.getString("name"));
                UserXML.setUserId(getApplication(),object1.getString("loginUserId"));
                UserXML.setImagePath(getApplication(),object1.getString("headPortrait"));
                UserXML.setUserId(getApplication(),object1.getString("loginUserId"));
                RongCloudXML.setTenantCode(getApplication(),object1.getString("tenantCode"));
                RongCloudXML.setSubjectenterprisetype(getApplication(),"subjectEnterpriseType",object1.getString("subjectEnterpriseType"));
                RongCloudXML.setMilkstationflag(getApplication(),"milkStationFlag",object1.getString("milkStationFlag"));
                RongCloudXML.setSubjectInfoId(getApplication(),object1.getString("subjectInfoId"));
                RongCloudXML.setUserToken(getApplication(),"token",object1.getString("token"));
//                showToast(RongCloudXML.getSubjectenterprisetype(getApplication(),"subjectEnterpriseType"));
                ActivityTaskManager.getInstance().closeAllActivity();
                GotoUtil.gotoActivity(RegisterAndLoginActivity.this, MainActivity.class);
                finish();

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @JavascriptInterface
        public void forgetPassword(Object msg) {
            go(ForgetPasswordActivity.class);

        }
        @JavascriptInterface
        public void reviewResults(Object msg) {
            go(ReviewResultsActivity.class);

        }

        @JavascriptInterface
        public void addExpertInfo(Object msg) {

            go(AddExpertInfoActivity.class);


        }
    }
}
